package org.hxzon.blogbackup.baidu.album;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.hxzon.blogbackup.baidu.BlogReader;
import org.hxzon.util.DebugUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class PhotoBackuper {
    public static final String albumListUrl = "http://hi.baidu.com/hxzon/album";
//	public static final Pattern pattern = Pattern.compile("imgarr\\[len\\]=(.*)");
    public static final Pattern pattern = Pattern.compile("psrc:\"([^\",]*)");

    public static List<BlogAlbum> exportBlogAlbumPhotoList(String name, String url, int photoNum) {
        int pageNum = (photoNum + 17) / 18;
        List<BlogAlbum> albums = new ArrayList<BlogAlbum>();
        for (int i = 0; i <= pageNum; i++) {
            try {

                Document doc = BlogReader.get(url + "/index/" + i);
                Element div = doc.getElementById("forimgs");
                String divHtml = div.html();
                DebugUtil.debug(divHtml);
                Matcher matcher = pattern.matcher(divHtml);
                while (matcher.find()) {
                    String matcherStr = matcher.group(1);
                    DebugUtil.info("find," + matcherStr);
                }
            } catch (Exception e) {
                DebugUtil.error("fetch album list error", e);
            }
        }
        return albums;
    }

    public static void main(String args[]) {
        exportBlogAlbumPhotoList("模板图片", "http://hi.baidu.com/hxzon/album/%C4%A3%B0%E5%CD%BC%C6%AC", 20);
        //http://hi.baidu.com/hxzon/album/item/ecd5982f19591b061e30895e.html
        //http://hiphotos.baidu.com/hxzon/abpic/item/ecd5982f19591b061e30895e.jpg
        //http://hiphotos.baidu.com/hxzon/pic/item/ecd5982f19591b061e30895e.jpg
    }
}
